{layout name="Layout/layout" /}
<link href="/bootstrap/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h3>正在导入 <span>批次号：{$bach_num}</span></h3>
                    <div id="process-animation"  hidden>
                        <div class="sk-spinner sk-spinner-circle" style="margin-left: 90px">
                            <div class="sk-circle1 sk-circle"></div>
                            <div class="sk-circle2 sk-circle"></div>
                            <div class="sk-circle3 sk-circle"></div>
                            <div class="sk-circle4 sk-circle"></div>
                            <div class="sk-circle5 sk-circle"></div>
                            <div class="sk-circle6 sk-circle"></div>
                            <div class="sk-circle7 sk-circle"></div>
                            <div class="sk-circle8 sk-circle"></div>
                            <div class="sk-circle9 sk-circle"></div>
                            <div class="sk-circle10 sk-circle"></div>
                            <div class="sk-circle11 sk-circle"></div>
                            <div class="sk-circle12 sk-circle"></div>
                        </div>
                        <span id="process-finished">1</span>
                        <span id="process-total">/{$count}</span>
                    </div>
                </div>
               <!-- <div class="ibox-content text-warning">
                    <h3 class="text-info">
                        已成功导入<span></span>条记录，以下借款记录导入失败，请根据提示进行修改后提交
                    </h3>
                    <h4>提醒</h4>
                    <p>"还款方式"请填写整数</p>
                    <ul class="text-error">
                        {volist name="repayment_type_map" id="vv" key="kk"}
                        <li>{$kk}：{$vv}; </li>
                        {/volist}
                    </ul>
                    <p>&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;</p>
                    <p>"银行代码(编号)："</p>
                    <ul class="text-error">
                        {volist name="bank_code_list" id="vv"}
                        <li>{$key}：{$vv}; </li>
                        {/volist}
                    </ul>
                </div>-->
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="text-navy"> 已成功导入 <span class="text-warning" id="success-count">0</span>条记录，以下借款记录导入失败，请根据提示进行修改后提交</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content text-warning">
                    <h4>提醒</h4>
                    <p>"还款方式"请填写整数</p>
                    <ul class="text-error">
                        {volist name="repayment_type_map" id="vv" key="kk"}
                        <li>{$kk}：{$vv}; </li>
                        {/volist}
                    </ul>
                    <p>--------------------</p>
                    <p>"银行代码(编号)："</p>
                    <ul class="text-error">
                        {volist name="bank_code_list" id="vv"}
                        <li>{$key}：{$vv}; </li>
                        {/volist}
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <?php foreach($result_date as $k => $vo){ ?>
        <div class="col-sm-6 element-insert for-count-form">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="form_{$k}" class="tr_data">
                        <input hidden name="info[{$k}][batch_number]" value="{$bach_num}" class="form_{$k}">
                        <input hidden name="info[{$k}][excle_type]" value="{$excle_type}" class="form_{$k}">
                        {volist name="vo" id="vv" }
                        <div class="form-group  {$key}"><!--has-error-->
                            <label class="col-sm-3 control-label">{$excle_key_map[$key]['title']}：</label>
                            <div class="col-sm-8">
                                <input name="info[{$k}][{$key}]" value="{$vv}" type="text" class="form-control" aria-required="true">
                                <span class="err-msg help-block m-b-none {$key}-msg">
                                    <!--<i class="fa fa-times-circle"></i>-->
                                </span>
                            </div>
                        </div>
                        {/volist}
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <strong class="text-warning error_msg"></strong>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button form-id="form_{$k}" class="btn btn-primary hidden submit" type="button">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <?php }?>
    </div>

</div>

<!-- Sweet alert -->
<script src="/bootstrap/js/content.js?v=1.0.0"></script>
<script src="/bootstrap/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="/static/js/plug/layer/layer.js"></script>
<script>
    $(document).ready(function () {
        var form_count = "<?php echo count($result_date);?>";
        var form_count = Number(form_count);

        $(".submit").click(function () {
            var form_id = $(this).attr('form-id');
            var formdata = $("#"+form_id).serialize();//序列化表格内容为字符串
            var this_but = $(this);
            var this_form = $("#"+form_id);
            this_form.find('.error_msg').html("正在提交...");
            this_but.addClass("hidden");
            var options = {
                url: "{$submit_url}",
                type: 'post',
                async:false,
                dataType: 'json',
                data:formdata,
                beforeSend: function () {
                    layer.msg('正在提交', {
                        icon: 16,
                        shade: 0.01,
                        time:1000000});
                },
                complete: function () {
                    layer.closeAll();
                },
                success: function (data) {
                    console.log(data);
                    var obj = eval(data);
                    var el_parent = this_but.parents('tr');
                    //先清除错误信息
                    this_form.find(".form-group").removeClass('has-error');
                    this_form.find(".form-group .err-msg").html('');
                    if(obj.code != 0){ //有错误信息
                        this_form.find('.submit_msg').hide();
                        this_form.find('.error_msg').html(obj.message);
                        this_form.find('.submit').removeClass('hidden');
                        //遍历错误信息
                        if(obj.hasOwnProperty('data') && obj.data.hasOwnProperty("arr_errorMsg")){
                            var erroMsg = obj.data.arr_errorMsg;
                            for(var key in erroMsg){
                                var class_name = key;
                                this_form.find('.'+class_name).addClass('has-error');
                                this_form.find('.'+class_name+'-msg').html(erroMsg[key]);
                            }
                        }
                    }
                    else { //没有错误 成功
                        form_count--;
                        this_form.parents('.element-insert').removeClass("for-count-form").remove();
                        var count = $("#success-count").html();
                        count = parseInt(count);
                        count++;
                        $("#success-count").html(count);
                    }
                },
                error: function () {
                    this_form.find('.error_msg').html("服务器错误");
                    this_form.find('.submit').removeClass('hidden');
                }
            };

            $.ajax(options);
            console.log($(".for-count-form").length);
            if(form_count<1){
                swal({
                    title: "操作完成",
                    text: "",
                    type: "success"
                }, function () {
                    window.location.href='/merchant/borrower/multipleadd';
                });
            }
        });

        $(".submit").each(function(index,el){
            $(this).click();
        });

    });
</script>
